package com.turnengine.client.global.announcement.bean;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Announcement.
 */
public class Announcement implements IAnnouncement, Comparable<IAnnouncement> {

	/** The id. */
	private int id = -1;
	/** The game id. */
	private int gameId = -1;
	/** The game name. */
	private String gameName = "";
	/** The version id. */
	private int versionId = -1;
	/** The version name. */
	private String versionName = "";
	/** The instance id. */
	private int instanceId = -1;
	/** The instance name. */
	private String instanceName = "";
	/** The user id. */
	private int userId = -1;
	/** The user name. */
	private String userName = "";
	/** The timestamp. */
	private long timestamp = 0;
	/** The subject. */
	private String subject = "";
	/** The body. */
	private String body = "";

	/**
	 * Creates a new Announcement.
	 */
	public Announcement() {
	}

	/**
	 * Creates a new Announcement.
	 * @param id the id
	 * @param gameId the game id
	 * @param gameName the game name
	 * @param versionId the version id
	 * @param versionName the version name
	 * @param instanceId the instance id
	 * @param instanceName the instance name
	 * @param userId the user id
	 * @param userName the user name
	 * @param timestamp the timestamp
	 * @param subject the subject
	 * @param body the body
	 */
	public Announcement(int id, int gameId, String gameName, int versionId, String versionName, int instanceId, String instanceName, int userId, String userName, long timestamp, String subject, String body) {
		setId(id);
		setGameId(gameId);
		setGameName(gameName);
		setVersionId(versionId);
		setVersionName(versionName);
		setInstanceId(instanceId);
		setInstanceName(instanceName);
		setUserId(userId);
		setUserName(userName);
		setTimestamp(timestamp);
		setSubject(subject);
		setBody(body);
	}

	/**
	 * Creates a new Announcement.
	 * @param announcement the announcement
	 */
	public Announcement(Announcement announcement) {
		setId(announcement.getId());
		setGameId(announcement.getGameId());
		setGameName(announcement.getGameName());
		setVersionId(announcement.getVersionId());
		setVersionName(announcement.getVersionName());
		setInstanceId(announcement.getInstanceId());
		setInstanceName(announcement.getInstanceName());
		setUserId(announcement.getUserId());
		setUserName(announcement.getUserName());
		setTimestamp(announcement.getTimestamp());
		setSubject(announcement.getSubject());
		setBody(announcement.getBody());
	}

	/**
	 * Creates a new Announcement.
	 * @param iAnnouncement the i announcement
	 */
	public Announcement(IAnnouncement iAnnouncement) {
		setId(iAnnouncement.getId());
		setGameId(iAnnouncement.getGameId());
		setGameName(iAnnouncement.getGameName());
		setVersionId(iAnnouncement.getVersionId());
		setVersionName(iAnnouncement.getVersionName());
		setInstanceId(iAnnouncement.getInstanceId());
		setInstanceName(iAnnouncement.getInstanceName());
		setUserId(iAnnouncement.getUserId());
		setUserName(iAnnouncement.getUserName());
		setTimestamp(iAnnouncement.getTimestamp());
		setSubject(iAnnouncement.getSubject());
		setBody(iAnnouncement.getBody());
	}

	/**
	 * Returns the id.
	 * @return the id.
	 */
	public int getId() {
		return id;
	}

	/**
	 * Returns the game id.
	 * @return the game id.
	 */
	public int getGameId() {
		return gameId;
	}

	/**
	 * Returns the game name.
	 * @return the game name.
	 */
	public String getGameName() {
		return gameName;
	}

	/**
	 * Returns the version id.
	 * @return the version id.
	 */
	public int getVersionId() {
		return versionId;
	}

	/**
	 * Returns the version name.
	 * @return the version name.
	 */
	public String getVersionName() {
		return versionName;
	}

	/**
	 * Returns the instance id.
	 * @return the instance id.
	 */
	public int getInstanceId() {
		return instanceId;
	}

	/**
	 * Returns the instance name.
	 * @return the instance name.
	 */
	public String getInstanceName() {
		return instanceName;
	}

	/**
	 * Returns the user id.
	 * @return the user id.
	 */
	public int getUserId() {
		return userId;
	}

	/**
	 * Returns the user name.
	 * @return the user name.
	 */
	public String getUserName() {
		return userName;
	}

	/**
	 * Returns the timestamp.
	 * @return the timestamp.
	 */
	public long getTimestamp() {
		return timestamp;
	}

	/**
	 * Returns the subject.
	 * @return the subject.
	 */
	public String getSubject() {
		return subject;
	}

	/**
	 * Returns the body.
	 * @return the body.
	 */
	public String getBody() {
		return body;
	}

	/**
	 * Sets the id.
	 * @param id the id to set.
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * Sets the game id.
	 * @param gameId the game id to set.
	 */
	public void setGameId(int gameId) {
		this.gameId = gameId;
	}

	/**
	 * Sets the game name.
	 * @param gameName the game name to set.
	 */
	public void setGameName(String gameName) {
		this.gameName = gameName;
	}

	/**
	 * Sets the version id.
	 * @param versionId the version id to set.
	 */
	public void setVersionId(int versionId) {
		this.versionId = versionId;
	}

	/**
	 * Sets the version name.
	 * @param versionName the version name to set.
	 */
	public void setVersionName(String versionName) {
		this.versionName = versionName;
	}

	/**
	 * Sets the instance id.
	 * @param instanceId the instance id to set.
	 */
	public void setInstanceId(int instanceId) {
		this.instanceId = instanceId;
	}

	/**
	 * Sets the instance name.
	 * @param instanceName the instance name to set.
	 */
	public void setInstanceName(String instanceName) {
		this.instanceName = instanceName;
	}

	/**
	 * Sets the user id.
	 * @param userId the user id to set.
	 */
	public void setUserId(int userId) {
		this.userId = userId;
	}

	/**
	 * Sets the user name.
	 * @param userName the user name to set.
	 */
	public void setUserName(String userName) {
		this.userName = userName;
	}

	/**
	 * Sets the timestamp.
	 * @param timestamp the timestamp to set.
	 */
	public void setTimestamp(long timestamp) {
		this.timestamp = timestamp;
	}

	/**
	 * Sets the subject.
	 * @param subject the subject to set.
	 */
	public void setSubject(String subject) {
		this.subject = subject;
	}

	/**
	 * Sets the body.
	 * @param body the body to set.
	 */
	public void setBody(String body) {
		this.body = body;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(7, 37);
		hash.append(id);
		hash.append(gameId);
		hash.append(gameName);
		hash.append(versionId);
		hash.append(versionName);
		hash.append(instanceId);
		hash.append(instanceName);
		hash.append(userId);
		hash.append(userName);
		hash.append(timestamp);
		hash.append(subject);
		hash.append(body);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof Announcement) {
			Announcement compare = (Announcement) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.id, compare.id);
			equals.append(this.gameId, compare.gameId);
			equals.append(this.gameName, compare.gameName);
			equals.append(this.versionId, compare.versionId);
			equals.append(this.versionName, compare.versionName);
			equals.append(this.instanceId, compare.instanceId);
			equals.append(this.instanceName, compare.instanceName);
			equals.append(this.userId, compare.userId);
			equals.append(this.userName, compare.userName);
			equals.append(this.timestamp, compare.timestamp);
			equals.append(this.subject, compare.subject);
			equals.append(this.body, compare.body);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(IAnnouncement compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.id, compare.getId());
		builder.append(this.gameId, compare.getGameId());
		builder.append(this.gameName, compare.getGameName());
		builder.append(this.versionId, compare.getVersionId());
		builder.append(this.versionName, compare.getVersionName());
		builder.append(this.instanceId, compare.getInstanceId());
		builder.append(this.instanceName, compare.getInstanceName());
		builder.append(this.userId, compare.getUserId());
		builder.append(this.userName, compare.getUserName());
		builder.append(this.timestamp, compare.getTimestamp());
		builder.append(this.subject, compare.getSubject());
		builder.append(this.body, compare.getBody());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		string.append("id", id);
		string.append("gameId", gameId);
		if (gameName != null) {
			string.append("gameName", gameName);
		}
		string.append("versionId", versionId);
		if (versionName != null) {
			string.append("versionName", versionName);
		}
		string.append("instanceId", instanceId);
		if (instanceName != null) {
			string.append("instanceName", instanceName);
		}
		string.append("userId", userId);
		if (userName != null) {
			string.append("userName", userName);
		}
		string.append("timestamp", timestamp);
		if (subject != null) {
			string.append("subject", subject);
		}
		if (body != null) {
			string.append("body", body);
		}
		return string.toString();
	}
}
